﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using winformchrome.server.model;

namespace winformchrome.server.controller
{
    class UserController
    {
        public String getUserDetail(String userId)
        {
            UserVO userVo = new UserVO();
            userVo.UserName="zhangsan";
            userVo.RealName="张三";
            List<String> orders = new List<string>();
            orders.Add("101");
            orders.Add("102");
            orders.Add("103");
            orders.Add("104");
            userVo.Orders=orders;
            string rsJson = Newtonsoft.Json.JsonConvert.SerializeObject(userVo);
            Console.WriteLine("输出：" + userId+",结果："+rsJson);
            return rsJson;
        }
        public Boolean checkUserLogin(String userName,String userPwd)
        {
            if ("admin".Equals(userName)&&"000000".Equals(userPwd))
            {
                return true;
            }
            return false;
        }
        public void logout()
        {
            //Process.GetCurrentProcess().Kill();
            //销毁浏览器控件
            // System.Diagnostics.Process.GetCurrentProcess().Kill();
            //browser.GetBrowser().CloseBrowser(false);
            //UI跨线程
            //CefSharp.Cef.Shutdown();
            //System.Environment.Exit(0);


            try
            {
                //获取chrome内核浏览器的所有进程
                Process[] processIdAry = Process.GetProcessesByName("CefSharp.BrowserSubprocess");
                //如果有这个进程运行那么就是
                if (processIdAry.Count() > 0)
                {
                    for (int i = 0; i < processIdAry.Count(); i++)
                    {
                        Console.WriteLine("第{0}个程序的ID:{1}", i, processIdAry[i].Id);
                        //杀死chrome进程
                        processIdAry[i].Kill();
                        Console.WriteLine("进程关闭成功！\n");
                    }
                }
                else
                {
                    Console.WriteLine("这个进程没有运行");
                }
            }
            catch
            {
                Console.WriteLine("无法关闭此进程！");
            }
            //杀死主进程
            Process.GetCurrentProcess().Kill();


        }
    }
}
